function scheduleHtmlParser(html) {
    let result = []
    let $ = cheerio.load(html, { decodeEntities: false })
    let config = {}

    try {
        config = JSON.parse($('#ltxhhzConfig').text())
    } catch (error) {}

    try {
        $('tbody')
            .children()
            .each(function (i, el) {
                if (i) {
                    const children1 = $(el).children()
                    for (let i1 = 0; i1 < children1.length; i1++) {
                        const el1 = children1.get(i1)

                        if (i1 === 0) {
                            let inner = $(el1).text().trim()
                            if (inner.includes('备注')) {
                                break
                            }
                        } else {
                            let cls = {
                                name: '',
                                teacher: '',
                                position: '',
                                day: getCorrectDay(i1),
                                weeks: [],
                                sections: []
                            }

                            $('.kbcontent', el1)
                                .children()
                                .each(function (i2, el2) {
                                    const str = $(el2).text().trim()
                                    if (!cls.name) {
                                        if (el2.prev && el2.prev.data && /^\-+$/.test(el2.prev.data.trim())) {
                                            return
                                        }
                                        if (el2.prev && el2.prev.data) {
                                            cls.name = el2.prev.data.trim()
                                        }
                                    } else {
                                        if (el2.name === 'font' && el2.attribs.title === '老师') {
                                            cls.teacher = $(el2).text().trim()
                                        } else if (el2.attribs && el2.attribs.title && el2.attribs.title.includes('教室')) {
                                            cls.position = str
                                        } else if (el2.attribs && el2.attribs.title && el2.attribs.title.includes('周次')) {
                                            cls.weeks = []

                                            const weekSectionMatch = str.match(/([\d-,]+)\(周\)\[([\d-]+)节\]/)
                                            if (weekSectionMatch) {
                                                weekSectionMatch[1]
                                                    .split(',')
                                                    .map(w => {
                                                        if (w.includes('-')) {
                                                            const arr = w.split('-')
                                                            const arr1 = Array(arr[1] - arr[0] + 1)
                                                                .fill()
                                                                .map((v, i) => +i + +arr[0].trim())
                                                            return arr1
                                                        } else {
                                                            return +w.trim()
                                                        }
                                                    })
                                                    .forEach(w => {
                                                        if (Array.isArray(w)) {
                                                            cls.weeks.push(...w)
                                                        } else {
                                                            cls.weeks.push(w)
                                                        }
                                                    })

                                                const sectionStr = weekSectionMatch[2]
                                                const sections = sectionStr.split('-').map(s => parseInt(s))
                                                const sectionCount = sections.length
                                                const startSection = sections[0]
                                                for (let s = 0; s < sectionCount; s++) {
                                                    cls.sections.push(startSection + s)
                                                }
                                            }
                                        } else if (el2.next && el2.next.type === 'text') {
                                            const text = el2.next.data.trim()
                                            if (/^\-+$/.test(text)) {
                                                if (!cls.weeks || cls.sections.length === 0) {
                                                    throw new Error('未匹配周次或节次')
                                                }
                                                pushUnique(result, cls)
                                                cls = {
                                                    name: '',
                                                    teacher: '',
                                                    position: '',
                                                    day: getCorrectDay(i1),
                                                    weeks: [],
                                                    sections: []
                                                }
                                            } else {
                                                if (config.isTeacher) {
                                                    if (/\d班/.test(text)) {
                                                        cls.teacher = text
                                                    }
                                                }
                                            }
                                        }
                                    }
                                })
                            if (cls.name && cls.weeks && cls.sections.length > 0) {
                                pushUnique(result, cls)
                            }
                        }
                    }
                }
            })

        console.log("最终解析结果：", result)
        return result
    } catch (error) {
        console.error(error)
        return []
    }
}

// 去重函数
function pushUnique(result, cls) {
    const exists = result.some(item =>
        item.name === cls.name &&
        item.teacher === cls.teacher &&
        item.position === cls.position &&
        item.day === cls.day &&
        JSON.stringify(item.weeks) === JSON.stringify(cls.weeks) &&
        JSON.stringify(item.sections) === JSON.stringify(cls.sections)
    )
    if (!exists) {
        result.push(cls)
    }
}

// 星期列索引 → 星期几
function getCorrectDay(columnIndex) {
    const mapping = {
        1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 1
    }
    return mapping[columnIndex] || columnIndex
}
